﻿using System;
using System.ServiceModel.DomainServices.Server;
using Arch.Common.IoC;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;

namespace Arch.DomainServices
{
    public class DomainServiceFactory : IDomainServiceFactory
    {
        public DomainService CreateDomainService(Type domainServiceType, DomainServiceContext context)
        {
            var domainService = (DomainService)ServiceLocator.Current.GetInstance(domainServiceType);
            domainService.Initialize(context);
            return domainService;
        }

        public void ReleaseDomainService(DomainService domainService)
        {
            if (domainService != null)
            {
                domainService.Dispose();
            }
        }
    }
}
